<?php
class Backend_LogController extends Zend_Controller_Action
{
	private $registry; // registry
	private $auth; // user-values
	private $settings; // board-settings
	private $baseUrl; // helper
	
	public function init()
	{		
		// registry
		$this->registry = Zend_Registry::getInstance();
		
		// settings
		$this->settings	= $this->registry->get('settings');
		
		// helper
		$baseUrl		= new MHDEV_View_Helper_BaseUrl();
		$this->baseUrl	= $baseUrl->BaseUrl();
		
		// auth
		$auth = Zend_Auth::getInstance();
		$this->view->auth = $auth->hasIdentity();
    	
		if($auth->hasIdentity())
		{
			$this->view->auth_role 			= $auth->getIdentity()->role;
			$this->view->username 			= $auth->getIdentity()->username;
			$this->view->auth_uid			= $auth->getIdentity()->uid;
			$this->view->unread_messages	= $auth->getIdentity()->count_unread_messages;
		}
		else
		{
			$this->view->username 	= $this->registry->get('lang')->_('guest');
		}

		$this->auth = $auth;
    	
		// lang
		$this->view->translate = $this->registry->get('lang');
		
		// include js
		$this->view->headScript()->appendFile($this->baseUrl . '/static/js/jquery-1.3.2.min.js');
		$this->view->headScript()->appendFile($this->baseUrl . '/static/js/backend.js');
	}
	
	public function indexAction()
	{
		// helper
		$baseurl	= new MHDEV_View_Helper_BaseUrl();
		
		// var
		$getPost	= $this->_request->getPost();
		
        // get log
        if($getPost && $getPost['log'])
        {
	        $log_file 	= '../application/data/' . $getPost['log'];
			$handle		= fopen($log_file, 'r');
			
			$array = array();
			
			$c=0;
			while(($content = fgetcsv ($handle, 1000, ";")) !== FALSE ) 
			{
				$array[$c]['timestamp'] = $content[0];
				$array[$c]['level'] 	= $content[1];
				$array[$c]['level_id'] 	= $content[2];
				$array[$c]['desc'] 		= $content[3];
				$c++;
			}
			
			$this->view->logCon 	= $array;
			$this->view->logSum		= $c;
			$this->view->logTitle	= $getPost['log'];
        }
        
		// view
		$this->view->logDir			= '../application/data/';
	}
}
?>